package com.friday.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.friday.dao.IndexDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {

    @Autowired
    private IndexDao indexDao;

    @RequestMapping("/typeSaleData")
    public JSONArray getTypeSale(){
        return indexDao.getTypeSale();
    }

    @RequestMapping("/saleRankData")
    public JSONArray getSaleRank(){
        return indexDao.getSaleRank();
    }

    @RequestMapping("/getCarousel")
    public JSONArray getCarousel(){
        return indexDao.getCarousel();
    }

    @RequestMapping("/getTradeInfo")
    public JSONObject getTradeInfo(@RequestParam("company_id") int company_id){
        JSONObject result = new JSONObject();
        result.put("orderSum",indexDao.getOrderCount(company_id));
        result.put("orderTypeSum",indexDao.getOrderTypeCount(company_id));
        result.put("saleSum",indexDao.getSaleCount(company_id));
        result.put("saleCountM",indexDao.getSaleCountByMonth(company_id));
        result.put("WQuoCount",indexDao.getWQuoCount(company_id));
        result.put("WInqCount",indexDao.getWInqCount(company_id));
        return result;
    }

    @RequestMapping("/getBasicInfo")
    public JSONObject get(){
        JSONObject result = new JSONObject();
        result.put("productCount",indexDao.getOnSalePd());
        result.put("customerCount",indexDao.getCustomerCount());
        result.put("saleSumTM",indexDao.getSaleSum());
        result.put("inquiryCount",indexDao.getInquiryCount());
        result.put("quotationCount",indexDao.getQuotationCount());
        result.put("orderCount",indexDao.getorderCount());
        return result;
    }

}
